<?php
$f_id		= array('id'=>'f_id', 'style'=>'display:none;', 'name'=>'id', 'value'=> set_value('id',$id));
$f_fullname	= array('id'=>'f_fullname', 'class'=>'span12 form-control', 'name'=>'fullname', 'value'=> set_value('fullname',$fullname));
$f_address1	= array('id'=>'f_address1', 'class'=>'span12 form-control', 'name'=>'address1', 'value'=>set_value('address1',$address1));
$f_email	= array('id'=>'f_email', 'class'=>'span12 form-control', 'name'=>'email', 'value'=>set_value('email',$email));
$f_phone	= array('id'=>'f_phone', 'class'=>'span12 form-control', 'name'=>'phone', 'value'=> set_value('phone',$phone));
echo form_input($f_id);
?>
<div class="modal" id="my-modal">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal">×</button>
		<h3><?php echo lang('address_form');?></h3>
	</div>
	<div class="modal-body">
		<div class="alert allert-error hide" id="form-error">
			<a class="close" data-dismiss="alert">×</a>
		</div>
		<div class="form-group">
			<label><?php echo lang('address_fullname');?></label>
            <div class="clear"></div>
			<?php echo form_input($f_fullname);?>
		</div>
		<div class="form-group">
			<label><?php echo lang('address_email');?></label>
             <div class="clear"></div>
			<?php echo form_input($f_email);?>
        </div>
        <div class="form-group">
			<label><?php echo lang('address_phone');?></label>
			<?php echo form_input($f_phone);?>
		</div>
		<div class="form-group">
			<label><?php echo lang('address');?></label>
             <div class="clear"></div>
			<?php echo form_input($f_address1);?>
		</div>
		<div class="form-group">
			<label>Tĩnh/TP</label>
			<?php echo form_dropdown('zone_id', @$zones_menu, set_value('zone_id', $zone_id), 'id="f_zone_id" class="span12 form-control"');?>
        </div>
		<div class="form-group">
			<label>Khu vực</label>
			<?php echo form_dropdown('area_id', @$area_menu, set_value('area_id', $area_id), 'id="f_area_id" class="span12 form-control"');?>
        </div>
	</div>
	<div class="modal-footer">
		<a href="#" class="btn" data-dismiss="modal"><?php echo lang('close');?></a>
		<a href="#" class="btn btn-primary" type="button" onclick="save_address(); return false;"><?php echo lang('form_submit');?></a>
	</div>
</div>

<script>
$('#f_zone_id').change(function(){
	$.post('<?php echo site_url('locations/get_zone_area');?>',{id:$(this).val()}, function(data) {
		$('#f_area_id').html("<option value=''> ---- Khu vực ---- </option>"+data);
	});
	
});
function save_address(){
	$.post("<?php echo site_url('secure/address_form');?>/"+$('#f_id').val(), {
																				fullname: $('#f_fullname').val(),
																				email: $('#f_email').val(),
																				phone: $('#f_phone').val(),
																				address1: $('#f_address1').val(),
																				location_zone: $('#f_zone_id').val(),
																				zone_area: $('#f_area_id').val(),
																			  },
		function(){
			window.location = "<?php echo site_url('secure/my_account');?>";
		});
}
</script>